package com.hollysys.hollimsa.biz.istio.virtualservice.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author wangyuxi
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class VirtualserviceDetailDTO  implements Serializable {

    private static final long serialVersionUID = 5579559492214056039L;
    @ApiModelProperty(value = "规则名称")
    private String ruleName;

    /** 访问方式 (public公网， cluster集群 )*/
    @ApiModelProperty(value = "访问方式 (public公网， cluster集群 )")
    private String requestType = "cluster";


    @ApiModelProperty(value = "路由类型(content基于请求内容, trafficRatio 基于流量比例)")
    /** 路由类型(content基于请求内容, trafficRatio 基于流量比例) */
    private String routerType = "content";

    @ApiModelProperty(value = "服务域名")
    /** 服务域名 */
    private String[] hosts;

    @ApiModelProperty(value = "网关")
    /** 网关 */
    private String[] gateways;

    @ApiModelProperty(value = "路由项")
    /** 路由项 */
    private HttpRoute[] http;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class HttpRoute implements Serializable {
        @ApiModelProperty(value = "匹配要激活的规则要满足的条件")
        private HTTPMatchRequest[] match;
        @ApiModelProperty(value = "http规则可以重定向或转发（默认）流量")
        private HTTPRouteDestination[] route;
    }


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class HTTPMatchRequest implements Serializable {

        @ApiModelProperty(value = "路由条件 uri")
        private String routeCondition;
        @ApiModelProperty(value = "匹配类型 exact prefix regex")
        private String matchType;
        @ApiModelProperty(value = "规则字符串")
        private String inputRule;
    }


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class HTTPRouteDestination implements Serializable {
        @ApiModelProperty(value = "Destination唯一标识应将请求/连接转发到的服务实例")
        private Destination destination;
        @ApiModelProperty(value = "要转发到服务版本的流量比例。（0-100）。各个目标之间的权重之和应为==100。如果规则中只有一个目标，则权重值将假定为100")
        private Integer weight;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class Destination implements Serializable {
        @ApiModelProperty(value = "服务注册表中的服务名称。从平台的服务注册表（例如Kubernetes服务，Consul服务等）")
        private String host;
        @ApiModelProperty(value = "服务中子集的名称。仅适用于网格内的服务。该子集必须在相应的DestinationRule中定义")
        private String subset;
        @ApiModelProperty(value = "指定要寻址的主机上的端口。如果服务仅公开单个端口，则不需要显式选择端口")
        private PortSelector port;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class PortSelector implements Serializable {
        @ApiModelProperty(value = "指定用于匹配或选择最终路由的端口号")
        private Integer number;
    }
}
